
public class MyQueue {
    public class ListNode{
        public ListNode next;
        public ListNode prev;
        public int val;

        public ListNode(int val) {
            this.val = val;
        }
    }

    public ListNode first;
    public ListNode last;

    public void offer(int val){
        ListNode newnode = new ListNode(val);
        if(first == null) {
            first = last = newnode;
        }else{
            last.next = newnode;
            newnode.prev = last;
            last = newnode;
        }
    }


    public int poll(){
        int val = 0;
        if(first == null){
            throw new QueueEmptyException("队列为空");
        }else{
            val = first.val;
            first = first.next;
            if(first!=null){
                first.prev = null;
            }

        }
        return val;
    }


    public int peek(){
        if(first == null){
            throw new QueueEmptyException("队列为空");
        }
        return first.val;
    }
}
